/*
 * FILE: safety_protection.c
 *
 * Functions:
 * Process Kill Prevention
 * Kernel modules prevent uninstallation
 * Software prevents uninstallation
 */
#include <linux/file.h>
#include <linux/fs.h>
#include <linux/slab.h>
#include <linux/xattr.h>

#define ATTR_KEY "security.cima"
#define ATTR_VALUE 'C'

//static LIST_HEAD(filepro_list);
static LIST_HEAD(procpro_list);
static LIST_HEAD(softpro_list);
static LIST_HEAD(kopro_list);

int my_file_open(struct file *file){
	int ret;
	char attr[1] = { 0 };
	struct path *my_path = &(file->f_path);
	struct dentry *my_dentry = my_path->dentry;
	struct qstr *my_qstr = &(my_dentry->d_name);
	struct inode *my_inode = my_dentry->d_inode;

	if(file){
		//if(strcmp(my_qstr->name, "zds") == 0){
			/*
			printk("lsm_hook:file_open=%s\n", my_qstr->name);
			printk("lsm_hook:d_name=%s\n", my_dentry->d_iname);
			printk("lsm_hook:d_name=%s\n", my_dentry->d_iname);
			*/

			ret = __vfs_getxattr(my_dentry, my_inode, ATTR_KEY, attr, sizeof(attr));
			if(ret > 0 && attr[0] == ATTR_VALUE)
				return -EBUSY;
			else
				return 0;
		//}
	}
	return 0;
}

